/*
 * DictionaryFileImplementation.h
 *
 *  Created on: Oct 19, 2012
 *      Author: bruno
 */

#ifndef DICTIONARYFILEIMPLEMENTATION_H_
#define DICTIONARYFILEIMPLEMENTATION_H_

#include <memory>
#include <iostream>
#include "IDictionaryStorage.h"
#include "../../physical_layer/file_system/TermOccurrenceSequentialFile.h"
#include "../../physical_layer/file_system/TermOccurrence.h"

using physical::TermOccurrence;
using physical::TermOccurrenceSequentialFile;

typedef std::shared_ptr<TermOccurrence> DICTIONARY_ENTRY;
typedef std::ios_base::openmode openmode;

class DictionaryFileImplementation: public IDictionaryStorage {
private:
	TermOccurrenceSequentialFile delegate;
public:
	DictionaryFileImplementation(const char fileName[], openmode mode,
			size_t readBufferSize, size_t writeBufferSize,
			bool serializeRandomKey) :
			delegate(fileName, mode) {
	}

	virtual ~DictionaryFileImplementation() {
	}

	virtual DICTIONARY_ENTRY get() {
		return DICTIONARY_ENTRY( new TermOccurrence (delegate.get()) );
	}

	virtual bool hasNext() {
		return delegate.hasNext();
	}

	virtual void put(DICTIONARY_ENTRY data) {
		delegate.put(*data.get());
	}

	virtual void close() {
		delegate.close();
	}
};

#endif /* DICTIONARYFILEIMPLEMENTATION_H_ */
